//
//  View2Controller.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/3/8.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit
import SnapKit
import SwiftyJSON

class View2Controller: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setButton()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}
// MARK: --网络请求按钮
extension View2Controller{
    // MARK: -设置网络请求按钮
    func setButton() -> Void {
        var top = 70
        let setp = 40
        let networkBut = createButton("网络请求", #selector(gotoNetwork), top, nil)
        let alertBut = createButton("提示框",  #selector(gotoAlert), top, networkBut)
        let collectionBut = createButton("Collection", #selector(gotoCollection), top, alertBut)
        let _ = createButton("等待", #selector(gotoWait), top, collectionBut)

        
        top += setp
        let pageBut = createButton("分页控制器", #selector(gotoPageControl), top, nil)
        let progressBut = createButton("进度条", #selector(gotoProgress), top, pageBut)
        let _ = createButton("查询条", #selector(gotoSearchBar), top, progressBut)

        

        top += setp
        let imageViewBut = createButton("UIImageView", #selector(gotoImageView), top, nil)
        let sliderBut = createButton("UISlider", #selector(gotoSlider), top, imageViewBut)
        let _ = createButton("UIPickerView", #selector(gotoPicker), top, sliderBut)
        
    
        top += setp
        let scrollViewBut = createButton("UIScrollView", #selector(gotoScrollView), top, nil)
        let stepperBut = createButton("UIStepper", #selector(gotoStepper), top, scrollViewBut)
        let _ = createButton("UISwitch", #selector(gotoSwitch), top, stepperBut)
        
        top += setp
        let animateView = createButton("音乐旋转动画", #selector(gotoAnimateView), top, nil)
        let webView = createButton("UIWebView", #selector(gotoWebView), top, animateView)
        let _ = createButton("沙盒目录", #selector(gotoShaHe), top, webView)
        
        top += setp
        let drawCircle = createButton("画圆", #selector(gotoDrawCircle), top, nil)
        let viewAnimate = createButton("UIView动画", #selector(gotoViewAnimate), top, drawCircle)
        let fileManager = createButton("文件管理", #selector(gotoFileManager), top, viewAnimate)
        let _ = createButton("文本框", #selector(gotoTextFile), top, fileManager)
        
        top += setp
        let plistBut = createButton("plist操作", #selector(gotoPlist), top, nil)
        let userDefaultBut = createButton("用户首选项", #selector(gotoUserDefault), top, plistBut)
        let _ = createButton("归档和解档", #selector(gotoArchive), top, userDefaultBut)
        
        top += setp
//        let _ = createButton("", <#T##newButAction: Selector##Selector#>, <#T##newButTop: Int##Int#>, <#T##leftButton: UIButton?##UIButton?#>)
        
        
    }
    
    
    
    func createButton(_ newButTitle:String,_ newButAction: Selector,_ newButTop:Int,_ leftButton:UIButton?) -> UIButton {
        let button = UIButton()
        button.setTitle(newButTitle, for: .normal)
        button.backgroundColor = UIColor.red
        self.view.addSubview(button)
        button.setDisplayOnRight(sourceButton: leftButton, top: newButTop)
        button.addTarget(self, action: newButAction, for: .touchUpInside)
        return button
    }
}
extension UIButton{
    //MARK: -设置button位置
    func setDisplayOnRight(sourceButton:UIButton?,top:Int) -> Void {
        
        self.snp.makeConstraints { (maker) in
            if sourceButton != nil {
                maker.left.equalTo(sourceButton!.snp.right).offset(5)
            }
            maker.top.equalTo(top)
        }
    }
}


